#ifndef DRAGGABLELABEL_H
#define DRAGGABLELABEL_H

#include <QLabel>
#include <QMouseEvent>
#include <QMainWindow>

class DraggableLabel : public QLabel
{
    Q_OBJECT

public:
    explicit DraggableLabel(QMainWindow *parent = nullptr);

signals:
    void mouseEntered(); // 鼠标进入时发送的信号
    void mouseLeft();    // 鼠标离开时发送的信号

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void enterEvent(QEvent *event) override; // 鼠标进入事件
    void leaveEvent(QEvent *event) override; // 鼠标离开事件

private:
    QMainWindow *_parent;
    bool dragging;
    QPoint dragStartPosition;
    QPoint offset;
    bool hasEntered; // 用于跟踪是否已经进入过
    bool hasLeft;    // 用于跟踪是否已经离开过
};

#endif // DRAGGABLELABEL_H